package adb.group.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;




import adb.group.entity.Entity;


public class TestDAO{
	public void testPerson() {
		Connection connection = null;
		PreparedStatement select = null;
		
		ResultSet resultSet = null;
		long  personID=0;
		
			try {
				connection = getConnection();
				String GET_Person_ID = "SELECT * FROM Person";  

				 select = connection.prepareStatement(GET_Person_ID);		
				 
				 resultSet = select.executeQuery();
							

				while( resultSet.next()){
					personID = resultSet.getLong(1);
					System.out.print("PersonID:"+personID);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 
			
			
			

		
		
	}
	
	protected void cleanupDatabaseResources(Connection connection,
			Statement statement, ResultSet resultSet) {
		try {
			if (resultSet != null) {
				resultSet.close();
			}
			if (statement != null) {
				statement.close();
			}
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	protected Connection getConnection() throws SQLException {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}					
		String url="jdbc:oracle:thin:@localhost:1521:orcl"; 
		String user="dbfp_dba"; 
		String password="dbfpdba"; 
		Connection connection= DriverManager.getConnection(url,user,password);
		
		return connection;
	}
}
